package beans;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoginBean implements Serializable
{
	private static final long serialVersionUID = 1l;
	
	public boolean getPassWord(String userName, String passWord)
	{	
		boolean validPW = false;
		
		System.out.println("test1");
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Totalitea", "root", "root");
			
			Statement stat = con.createStatement();
			ResultSet res = stat.executeQuery("SELECT password FROM totalitea WHERE username = " + "'" + userName + "'");
			if (res.next())
			{
				if (res.getString("password").equals(passWord))
				{
					validPW = true;
				}
			}
			res.close();
			stat.close();
			con.close();
		}
		catch(SQLException | ClassNotFoundException except)
		{
			System.err.println(except.getMessage());
		}
		System.out.println(validPW);
		return validPW;
	}
	
	public boolean getUserName(String userName)
	{
		boolean validUN = false;
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Totalitea", "root", "root");
			System.out.println("test8");
			Statement stat = con.createStatement();
			ResultSet res = stat.executeQuery("SELECT username FROM customer WHERE username = " + "'" + userName + "'");
			if (res.next())
			{
				if(res.getString("userName").equals(userName))
				{
					validUN = true;
				}
				else
				{
					validUN = false;
				}
			}
			else
			{
				validUN = false;
			}
			res.close();
			stat.close();
			con.close();
		}
		catch(SQLException | ClassNotFoundException except)
		{
			System.err.println(except.getMessage());
		}
		System.out.println(validUN);
		return validUN;
	}
}